home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17142 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  50 lines

  1. Path: nntp.teleport.com!usenet
  2. From: Jeff Grossman <grossman@teleport.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Default Constructors
  5. Date: 13 Apr 1996 21:09:28 GMT
  6. Organization: Teleport - Portland's Public Access (503) 220-1016
  7. Message-ID: <4kp568$3ph@nadine.teleport.com>
  8. References: <316F2B88.5FC4@psych.stanford.edu>
  9. NNTP-Posting-Host: ip-pdx10-19.teleport.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.2N (Windows; I; 16bit)
  14.  
  15. Nick Cassimatis <nick@psych.stanford.edu> wrote:
  16. >I'm having trouble getting default constructors to work in another 
  17. >class' constructor: e.g.,
  18. >
  19. >class position {
  20. >    int x,y,z;
  21.  
  22. try adding:
  23.  
  24. public:
  25.  
  26. >    position() {x = y = z = 0;};
  27. >    position(int, int, int);
  28. >};
  29. >
  30. >What exactly is meant by "access"? And why wouldn't I have it to an 
  31. >object that's already been declared?
  32. >
  33. >-Nick
  34.  
  35. The default access attribute for class members is "private". Without
  36. adding the "public" section, your contructors are not accessible
  37. outside the class.
  38.  
  39. This does not make private or proected constructors uselss. Protected
  40. constructors are accesible to friends of the class. Also, it is a
  41. common technique to define and make non-public default, copy, and
  42. assignment constructors if such operations are not to be permitted.
  43.  
  44. You may want to read more about these attributes in a C++ book.
  45.  
  46. Hope this helps.
  47. Jeff
  48.  
  49.  
  50.